//
//  Person.m
//  消息动态解析
//
//  Created by 崔博 on 2018/8/2.
//  Copyright © 2018年 崔博. All rights reserved.
//

#import "Person.h"
#import <objc/runtime.h>
@implementation Person

// 方法结构体
struct method_t {
    SEL sel;
    char *types;
    IMP imp;
};
//void c_other(id self,SEL _cmd)
//{
//    NSLog(@"c_other - %@ - %@",self,NSStringFromSelector(_cmd));
//}
//- (void)other
//{
//    NSLog(@"%s",__func__);
//}
//+ (BOOL)resolveInstanceMethod:(SEL)sel
//{
//    if (sel == @selector(test))
//    {
//        // 获取其他方法
////        struct method_t *otherMethod = (struct method_t *)class_getInstanceMethod(self, @selector(other));
////        NSLog(@"%s---%s---%p",otherMethod->sel,otherMethod->types,otherMethod->imp);
//        Method m = class_getInstanceMethod(self, @selector(other));
//        class_addMethod(self, sel, (IMP)c_other, "v:16@0:8");
//        NSLog(@"我调用了");
//        return NO;
//    }
//    return [super resolveInstanceMethod:sel];
//}
//+ (BOOL)resolveInstanceMethod:(SEL)sel
//{
//    if (sel == @selector(test))
//    {
//        // 获取其他方法
//        struct method_t *otherMethod = (struct method_t *)class_getInstanceMethod(self, @selector(other));
//        NSLog(@"%s---%s---%p",otherMethod->sel,otherMethod->types,otherMethod->imp);
//
//        class_addMethod(sel, sel, otherMethod->imp, otherMethod->types);
//        NSLog(@"我调用了");
//        return NO;
//    }
//    return [super resolveInstanceMethod:sel];
//}

// 类方法
+ (BOOL)resolveClassMethod:(SEL)sel
{
    if (sel == @selector(test)) {
        class_addMethod(object_getClass(self), sel, (IMP)c_other,  "v:16@0:8");
        return YES;
    }
    return YES;
}
void c_other(id self,SEL _cmd)
{
    NSLog(@"c_other - %@ - %@",self,NSStringFromSelector(_cmd));
}
@end
